﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace eAssessment.lists
{
    class MChoiceAnswerTemplateListManager
    {
        public int AddMultipleChoiceAnswerTemplate(string answer, bool isCorrect, int questionID,SPWeb listWeb)
        {
            if (answer != null && answer.Length > 1)
            {
                SPListItemCollection itemCollection = listWeb.Lists[ListAccessManager.MChoiceAnswerTemplateListName].Items;
                SPListItem answerItem = itemCollection.Add();
                if (answer.Length > 15)
                {
                    answerItem["Titel"] = answer.Substring(0, 15);
                }
                else
                {
                    answerItem["Titel"] = answer;
                }
                answerItem["Answer"] = answer;
                answerItem["IsCorrect"] = isCorrect;
                answerItem["QuestionTemplateID"] = questionID;
                answerItem.Update();
                return answerItem.ID;
            }
            return -1;
        }
    }
}
